<?php
/**
 * 用户
 * 
 * Created	: 2010-11-08
 * Modified : 2010-11-08
 * @author  : 陈立强
 */
class SUser extends User {
	
	/**
	 * 用户登录
	 * @param string $username 用户名
	 * @param string $password 密码
	 */
	public static function login($username)
	{
		global $L;
		$ret = parent::login($username);
		if ($ret) {
			return array(
				'val' => true,
				'data' => array(
					'uid' => $_SESSION['uid']
				)
			);
		} else {
			return array(
				'val' => false,
				'msg' => $L['login_failure']
			);
		}
	}
	
	/**
	 * 注销登录状态
	 */
	public static function logout()
	{
		$ret = parent::logout();
		return array(
			'val' => $ret
		);
	}
	
	/**
	 * 用户是否已创建角色
	 * @param  $uid
	 */
	public static function isCreatedRole()
	{
		$ret = parent::isCreatedRole();
		return array(
			'val' => true,
			'data'	=> array(
				'created_role'	=> $ret,
			)
		);
	}
		
	/**
	 * 用户是否存在
	 * @param string $username
	 */
	public static function isUserExists($username)
	{
		$ret = parent::isUserExists($username);
		return array(
			'val' => true,
			'data'	=> array(
				'exists'		=> $ret,
				'redirect_url'	=> $GLOBALS['loginUrl']
			)
		);
	}
	
	/**
	 * 读取用户信息
	 * @param int $r_id
	 */
	public static function read($uid)
	{
		$user = parent::read($uid, '*', true);
		return array(
			'val' => true,
			'data'   => $user
		);
	}
	
	/**
	 * 搜索用户
	 * @param int $uid
	 * @param string $name
	 */
	public static function search($uid, $name)
	{
		global $DB, $L;
		
		$user = parent::search($uid, $name);
		
		return array(
			'val'	=> true,
			'data'	=> $user
		);
	}
	
	/**
	 * 获取黑名单列表
	 * @param int $uid
	 */
	public static function getFileterList($uid)
	{
		global $DB, $L;
		
		$list = parent::getFileterList($uid);
		
		return array(
			'val'	=> true,
			'data'	=> $list
		);
	}
	
	/**
	 * 判断用户是否VIP玩家
	 * @param int $uid 用户ID
	 */
	public static function isVip($uid)
	{
		$ret = parent::isVip($uid);
		if ($ret) {
			return array(
				'val' => true
			);
		} else {
			return array(
				'val' => false
			);
		}
	}
}